package de.uni.muenster.idw2.location;

import android.R;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
import de.uni.muenster.idw2.data.Building;
import de.uni.muenster.idw2.location.bluetooth.service.PositioningService;
import de.uni.muenster.idw2.location.bluetooth.service.PositioningServiceInterface;
import de.uni.muenster.idw2.location.wifi.Comparison;


public class LocationController {
	
	private static BluetoothController bluetoothController;
	private static boolean activeBluetooth;
	private static boolean activeWIFI;

	
	public static void startAllLocationUpdates(Building building, Activity act){
//		SharedPreferences preferences = act.getSharedPreferences(name, mode)
		SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(act);
		activeBluetooth = preferences.getBoolean(act.getResources().getString(de.uni.muenster.idw2.R.string.options_bluetooth), true);
		activeWIFI = preferences.getBoolean(act.getResources().getString(de.uni.muenster.idw2.R.string.options_wifi), true);
		Log.i("Receiver Status", "WIFI: "+activeWIFI+" - Bluetooth: "+activeBluetooth);
		
		if(activeWIFI){
			startWIFIUpdate(building, act);
		}
		
		if(activeBluetooth){
			startBluetoothUpdate(building, act);
		}
	}
	
	public static void stopAllLocationUpdates(Activity act){
		
		if(activeWIFI){
			stopWIFIUpdate(act);
		}
		
		if(activeBluetooth){
			stopBluetoothUpdate();
		}
	}
	
	
	public static void startBluetoothUpdate(Building building, Activity act){
		bluetoothController = new BluetoothController(act);
		bluetoothController.startService();
	}
	
	public static void stopBluetoothUpdate(){
		bluetoothController.stopService();
	}
	
	
	public static void startWIFIUpdate(Building building, Activity act){
		Intent intent = new Intent(act, Comparison.class);
		act.startService(intent);
	}
	
	public static void stopWIFIUpdate(Activity act){
		Intent intent = new Intent(act, Comparison.class);
		act.stopService(intent);
	}





}
